<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>THREE</title>
    <script src="../../node_modules/three/build/three.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>

</body>
<script type="module">
    //创建场景，几何体与材质
    const scene = new THREE.Scene();
    const geometry = new THREE.BoxGeometry(50, 50, 50);
    const material = new THREE.MeshBasicMaterial({
        color: 0xcccccc
    });

    const mesh = new THREE.Mesh(geometry, material)
    scene.add(mesh);

    //系统坐标系绘制-----------------------------------------
    var axesHelper = new THREE.AxesHelper(24);
    scene.add(axesHelper);

    //网格线绘制
    var grid = new THREE.GridHelper(600, 20, 0xFF0000, 0x444444);
    grid.material.opacity = 0.4;
    grid.material.transparent = true;
    // grid.rotation.x = Math.PI / 2.0;
    scene.add(grid);
    //--------------------------------------------------------
    const height = window.innerHeight;
    const width = window.innerWidth;

    const camera = new THREE.OrthographicCamera(width / -2, width / 2, height / 2, height / -2, 1, 1000);
    camera.position.set(200, 200, 200);
    camera.lookAt(scene.position); //设置相机方向(指向的场景对象)

    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height);
    renderer.setClearColor(0xb9d3ff);

    document.body.appendChild(renderer.domElement); //body元素中插入canvas对象

    function render() {
        renderer.render(scene, camera); //执行渲染操作
        mesh.rotateY(0.02); //每次绕y轴旋转0.01弧度
        requestAnimationFrame(render); //请求再次执行渲染函数render
    }
    render();
</script>

</html>